package com.class05.cookie5;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/5 9:15
 */
@Controller
@RequestMapping("cookie")
@ResponseBody
public class CookieController {
    @RequestMapping("getCookie")
    public String getCookie(@CookieValue("cookieName") String value){
        System.out.println("value = " + value);
        return value;
    }
    @GetMapping("saveCookie")
    public String saveCookie(HttpServletResponse response){
        Cookie cookie = new Cookie("cookieName","root");
        response.addCookie(cookie);
        return "ok";
    }

}
